package controller

import (
	"class_bff/global"
	"class_bff/pkg"
	"encoding/json"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func ClassComment(c *gin.Context) {
	userId := c.PostForm("user_id")
	classId := c.PostForm("class_id")
	comment := c.PostForm("comment")
	userIdInt, _ := strconv.Atoi(userId)
	classIdInt, _ := strconv.Atoi(classId)
	if userIdInt == 0 || classIdInt == 0 || comment == "" {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": -1,
			"msg":  "参数不能为空",
			"data": nil,
		})
		return
	}
	var data = global.Comments{
		UserId:  userIdInt,
		ClassId: classIdInt,
		Comment: comment,
	}
	marshal, _ := json.Marshal(data)
	pkg.SimpleProducer("class_comment", string(marshal))

	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "添加评论成功",
		"data": nil,
	})
	return
}
